{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "41782e9f",
   "metadata": {},
   "source": [
    "## sklearn\n",
    "\n",
    "sklearn是一个Python第三方提供的非常强力的机器学习库，它包含了从数据预处理到训练模型的各个方面。使用scikit-learn中可以极大的节省我们编写代码的时间以及减少我们的代码量，使我们有更多的精力去分析数据分布，调整模型和修改超参。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7fb36fcd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 432x288 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPoAAAECCAYAAADXWsr9AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAL40lEQVR4nO3dW4hd9RXH8d+vY7xGSaxWJBHtSAmIUHNBKgFpNYpWsS81RFCotCQPrRha0NiX4ptPYh+KELxU8IajBoq01gQVEVrtTIz1MrFoiJhEHSWRGAsR4+rD2SkxnTp7xv3/z5mzvh845MzMmb3WzOR39t7n7L2XI0IABtu3ZrsBAOURdCABgg4kQNCBBAg6kABBBxLoi6DbvsL2W7bftr2hcK37bE/Yfr1knSPqnWX7Odvjtt+wfXPhesfbftn2q02920vWa2oO2X7F9lOlazX1dtp+zfY226OFay2w/bjt7c3f8KKCtZY0P9Ph237b6ztZeETM6k3SkKR3JA1LOlbSq5LOK1jvYknLJL1e6ec7U9Ky5v7Jkv5V+OezpPnN/XmSXpL0g8I/468lPSzpqUq/052STqtU6wFJv2juHytpQaW6Q5I+kHR2F8vrhzX6hZLejogdEfG5pEcl/aRUsYh4QdLeUsufpN77EbG1uf+ppHFJiwrWi4g40Hw4r7kVOyrK9mJJV0m6p1SN2WL7FPVWDPdKUkR8HhGfVCp/qaR3IuLdLhbW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axwk6UpJWyPiw8m+GBEbJW2UBv80VWCumc6m+3Visx2Yk1oF3faJki6T9GTZdgCU0HYk078lfbtwLwAK4cg4IAGCDiRA0IEECDqQAEEHEiDoQAIEHUiAoAMJEHQggVKz1z6SNJNz1k+T9HHH7fRDLepRr1a9syPi9KM/WSToM2V7NCJWDFot6lFvtuux6Q4kQNCBBPot6BsHtBb1qDer9fpqHx1AGf22RgdQAEEHEiDoQAIEHUiAoAMJ/AchD47vy2xCkAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 288x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn.datasets import load_digits\n",
    "import matplotlib.pyplot as plt \n",
    "from sklearn.cluster import KMeans\n",
    "\n",
    "# load digital data\n",
    "digits, dig_label = load_digits(return_X_y=True)\n",
    "\n",
    "# draw one digital\n",
    "plt.gray() \n",
    "plt.matshow(digits[0].reshape([8, 8])) \n",
    "plt.show() \n",
    "\n",
    "# calculate train/test data number\n",
    "N = len(digits)\n",
    "N_train = int(N*0.8)\n",
    "N_test = N - N_train\n",
    "\n",
    "# split train/test data\n",
    "x_train = digits[:N_train, :]\n",
    "y_train = dig_label[:N_train]\n",
    "x_test  = digits[N_train:, :]\n",
    "y_test  = dig_label[N_train:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "837a7563",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAA9CAYAAACEJCMYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAP5UlEQVR4nO2da2xU1RbH/3tmGOjLWuUlDxEUQVBvJYgKH9REsGqU6Afh4iNGTY2KCR804YOYgPEBomKiUYhRwYSgVjBXBQENAikmAvK4PAoW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lcpO6IXLm0m0ucZT1WgzJTc31/K7STeib3y86bJ8+XJj09UaADv9aMyYMdbQ7dWrV5s3bKdvlLRZPX78eMs3Y8YMY/MbnqcNxgsFOb0gaVOfD0+ni3Xy8ubMmWNtp/omTR/APCWRNrH59AP0s8XFxVYT89133zX2zp07k9bEm+v0YcRX96DnqaCgwJqeoLvOvBj0LY8OqafhB8AOfXAdNN0yHdAHP189hh6fTZs2Wb50v7HSkChflJrOGLhkyRLLt379+rTqomGsw4cPW76FCxcam4ZGgc4peD/99FPSmiQ9TxAEweNIRS0IguBxpKIWBEHwOKonekCVUvUAmgC4GnLO6O+gnBFa6wH8j6LD0zqOOSxDdIiOi0GHEy1d6gDQEczuiX8AdnihHNHhTR1ShpTRm8pItRwJfQiCIHgcqagFQRA8Tk9W1J0mbspSOaIjvd9PZzlShpTRW8pIqZwe6UwUBEEQ0oeEPgRBEDyOVNSCIAgep0cqaqVUiVLqkFKqUik1N4VyqpRS/1VK7VZK7ej+G6JDdIgO0XFx6QCQ/jxqAH4ARwCMAhAEsAfAOJdlVQHoLzpEh+gQHb1RR+xfT7xRTwJQqbU+qrVuAbAKwPQe2I/oEB2iQ3Rc7DoA9EzoYyiAarJdc/5vboit1bjz/FpmokN0iA7R0Zt0AHC+ZmIydDV7vdscwG7XahQdokN0iI6LWAeAnnmjrgEwnGwPA3DCTUGarNUIILZWo+gQHaJDdPQWHaaQtP5Dx1v6UQAjcSEIP95FOXkACoi9DUCJ6BAdokN09BYdsX9pD31orduUUrMBrEdHz+knWuv9LopKaa1G0SE6RIfo+H/XEUOGkAuCIHgcGZkoCILgcaSiFgRB8DhSUQuCIHgcqagFQRA8jlTUgiAIHkcqakEQBI8jFbUgCILH+R/UhbDun+c+6wAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 10 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# do kmeans\n",
    "kmeans = KMeans(n_clusters=10, random_state=0).fit(x_train)\n",
    "\n",
    "# kmeans.labels_ - output label\n",
    "# kmeans.cluster_centers_ - cluster centers\n",
    "\n",
    "# draw cluster centers\n",
    "fig, axes = plt.subplots(nrows=1, ncols=10)\n",
    "for i in range(10):\n",
    "    img = kmeans.cluster_centers_[i].reshape(8, 8)\n",
    "    axes[i].imshow(img)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
